/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 27 14:15
*/
KISSY.add("menubutton/menubutton-xtpl",["component/extension/content-xtpl"],function(k,d,i,h){return function(f){var c,e;c=this.config.utils;"undefined"!==typeof h&&h.kissy&&(e=h);var j=c.renderOutput,a=c.runInlineCommand;c="";var b={},g=[];g.push("component/extension/content-xtpl");b.params=g;e&&(d("component/extension/content-xtpl"),b.params[0]=e.resolveByName(b.params[0]));e=a(this,f,b,"include",1);c+=j(e,!1);c+='\n<div class="';e={};b=[];b.push("dropdown");e.params=b;e=a(this,f,e,"getBaseCssClasses",
2);c+=j(e,!0);c+='">\n    <div class="';e={};b=[];b.push("dropdown-inner");e.params=b;f=a(this,f,e,"getBaseCssClasses",3);c+=j(f,!0);return c+'">\n    </div>\n</div>'}});
KISSY.add("menubutton/render",["button","./menubutton-xtpl","component/extension/content-render"],function(k,d){var i=d("button"),h=d("./menubutton-xtpl"),f=d("component/extension/content-render");return i.getDefaultRender().extend([f],{decorateDom:function(c){var e=this.control,d=e.get("prefixCls"),c=c.one("."+d+"popupmenu"),a=c[0].ownerDocument.body;a.insertBefore(c[0],a.firstChild);a=this.getComponentConstructorByNode(d,c);e.setInternal("menu",new a({srcNode:c,prefixCls:d}))},beforeCreateDom:function(c){k.mix(c.elAttrs,
{"aria-expanded":!1,"aria-haspopup":!0})},_onSetCollapsed:function(c){var e=this.$el,d=this.getBaseCssClass("open");e[c?"removeClass":"addClass"](d).attr("aria-expanded",!c)}},{ATTRS:{contentTpl:{value:h}}})});
KISSY.add("menubutton/control",["node","button","./render"],function(k,d){function i(a){a.target.isMenuItem&&this.get("collapseOnClick")&&this.set("collapsed",!0)}function h(a){a.target.isMenu&&(a=a.newVal,this.el.setAttribute("aria-activedescendant",a&&a.el.id||""))}var f=d("node"),c=d("button"),e=d("./render"),j=f.KeyCode;return c.extend({isMenuButton:1,_onSetCollapsed:function(a){var b=this.get("menu");if(a)b.hide();else if(a=this.$el,!b.get("visible")){var g={node:a,points:["bl","tl"],overflow:{adjustX:1,
adjustY:1}};k.mix(b.get("align"),g,!1);this.get("matchElWidth")&&(b.render(),g=b.get("el"),g=(parseInt(g.css("borderLeftWidth"))||0)+(parseInt(g.css("borderRightWidth"))||0),b.set("width",b.get("align").node[0].offsetWidth-g));b.show();a.attr("aria-haspopup",b.get("el").attr("id"))}},bindUI:function(){this.on("afterHighlightedItemChange",h,this);this.on("click",i,this)},handleKeyDownInternal:function(a){var b=a.keyCode,g=""+a.type,l=this.get("menu");if(b===j.SPACE){if(a.preventDefault(),"keyup"!==
g)return}else if("keydown"!==g)return;if(l.get("rendered")&&l.get("visible"))return a=l.handleKeyDownInternal(a),b===j.ESC?(this.set("collapsed",!0),!0):a;if(b===j.SPACE||b===j.DOWN||b===j.UP)return this.set("collapsed",!1),!0},handleClickInternal:function(){this.set("collapsed",!this.get("collapsed"))},handleBlurInternal:function(a){this.callSuper(a);this.set("collapsed",!0)},addItem:function(a,b){this.get("menu").addChild(a,b)},removeItem:function(a,b){this.get("menu").removeChild(a,b)},removeItems:function(a){var b=
this.get("menu");b&&(b.removeChildren?b.removeChildren(a):b.children&&(b.children=[]))},getItemAt:function(a){var b=this.get("menu");return b.get("rendered")&&b.getChildAt(a)},_onSetDisabled:function(a){a||this.set("collapsed",!0)},destructor:function(){this.get("menu").destroy()}},{ATTRS:{matchElWidth:{value:!0},collapseOnClick:{value:!1},menu:{value:{},getter:function(a){a.isControl||(a.xclass=a.xclass||"popupmenu",a=this.createComponent(a),this.setInternal("menu",a));return a},setter:function(a){a.isControl&&
a.setInternal("parent",this)}},collapsed:{value:!1,view:1},xrender:{value:e}},xclass:"menu-button"})});
KISSY.add("menubutton/select",["node","./control"],function(k,d){function i(g){var a=g.get("menu"),a=a.children||a.get&&a.get("children")||[],g=g.get("value"),b,c;for(c=0;c<a.length;c++)if(b=a[c],h(b)===g)return b;return null}function h(a){var b;if(a)if(a.get){if(void 0===(b=a.get("value")))b=a.get("textContent")||a.get("content")}else if(void 0===(b=a.value))b=a.textContent||a.content;return b}function f(a){var b=a.get("menu"),c=a.get("value"),a=b&&b.get&&b.get("children");k.each(a,function(a){a&&
a.set&&a.set("selected",h(a)===c)})}function c(a){var b=i(this),c=this.get("menu");a.target===c&&((a=b||c.getChildAt(0))&&a.set("highlighted",!0),b&&b.set("selected",!0))}function e(a){var b=i(a),c=b&&(b.textContent||b.get&&b.get("textContent")),b=b&&(b.content||b.get&&b.get("content"));a.set("content",c||b||a.get("defaultCaption"))}function j(a){a=a.target;if(a.isMenuItem){var a=h(a),b=this.get("value");this.set("value",a);a!==b&&this.fire("change",{prevVal:b,newVal:a})}}var a=d("node"),b=d("./control").extend({bindUI:function(){this.on("click",
j,this);this.on("show",c,this)},removeItems:function(){this.callSuper.apply(this,arguments);this.set("value",null)},removeItem:function(a,b){this.callSuper(a,b);a.get("value")===this.get("value")&&this.set("value",null)},_onSetValue:function(){f(this);e(this)},_onSetDefaultCaption:function(){e(this)}},{ATTRS:{value:{},defaultCaption:{value:""},collapseOnClick:{value:!0}},decorate:function(c,d){c=k.one(c);d=d||{};d.elBefore=c;var e,h=[],f,i=null,j=c.val();c.all("option").each(function(a){var b={xclass:"option",
content:a.text(),elCls:a.attr("class"),value:a.val()};j===a.val()&&(i={content:b.content,value:b.value});h.push(b)});d.menu=d.menu||d.menuCfg||{};d.menu.children=h;delete d.menuCfg;f=(new b(k.mix(d,i))).render();if(e=c.attr("name")){var m=(new a('<input type="hidden" name="'+e+'" value="'+j+'">')).insertBefore(c,void 0);f.on("afterValueChange",function(a){m.val(a.newVal||"")})}c.remove();return f},xclass:"select"});return b});
KISSY.add("menubutton/option",["menu"],function(k,d){return d("menu").Item.extend({},{ATTRS:{selectable:{value:!0},textContent:{}},xclass:"option"})});KISSY.add("menubutton",["menubutton/control","menubutton/select","menubutton/option"],function(k,d){var i=d("menubutton/control"),h=d("menubutton/select"),f=d("menubutton/option");i.Select=h;i.Option=f;return i});
